﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ExtraOpdrachten
{
    public partial class Opdracht5 : System.Web.UI.Page
    {
        #region Fields
        private const float YEN = 0.0074f;
        private const float YUAN = 0.1402f;
        private const float DOLLAR = 0.8754f;
        private const float GULDEN = 0.4911f;
        private const float ROEBEL = 0.0135f;
        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void RadioButtonListValuta_SelectedIndexChanged(object sender, EventArgs e)
        {
            float money = 0;
            float convertedMoney = 0;
            float rate = 1;
            if (TextBoxMoney.Text.Trim() == "")
            {
                LabelResult.Text = "Voer a.u.b. eerst een bedrag in";
                LabelResult.ForeColor = Color.Red;
                return;
            }
            else
            {
                LabelResult.ForeColor = Color.Black;
                money = float.Parse(TextBoxMoney.Text);
            }
            switch (RadioButtonListCurrency.SelectedIndex)
            {
                case 0:
                    rate = DOLLAR;
                    break;
                case 1:
                    rate = GULDEN;
                    break;
                case 2:
                    rate = YUAN;
                    break;
                case 3:
                    rate = YEN;
                    break;
                case 4:
                    rate = ROEBEL;
                    break;
            }

            if (CheckBoxReverse.Checked)
            {
                convertedMoney = money * rate;
                LabelResult.Text = TextBoxMoney.Text + " " +
                    RadioButtonListCurrency.SelectedItem.ToString() +
                    " is gelijk aan " + convertedMoney.ToString("0.00") +
                    " euro.";
            }
            else
            {
                convertedMoney = money / rate;
                LabelResult.Text = TextBoxMoney.Text + " euro is gelijk aan " +
                    convertedMoney.ToString("0.00") + " " +
                    RadioButtonListCurrency.SelectedItem.ToString() + ".";
            }
        }


    }
}